
import MebcardtypeZK from '../../views/mall/MebcardtypeZK.vue'
let extension = {
  components: {//动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: '',//{ template: "<div>扩展组xx件</div>" },
    gridBody: MebcardtypeZK,
    gridFooter: '',
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: '',
    modelBody: '',
    modelFooter: ''
  },
  data () {
    return {
      grantorid: '',
      grantor: '',
      cardmodel: '',
      cardTypeList: []
    }
  },
  buttons: {
    view: [
      {
        name: "新建",
        icon: 'md-add',
        value: 'XJ',
        class: '',
        type: 'error',
        index: 1,//显示的位置
        onClick: function () {
          this.$refs.gridBody.model = true
          this.$refs.gridBody.title = '新建'
          this.$nextTick(() => {
            this.$refs.gridBody.editFormOptions[0][0] = {
              title: "卡模板",
              field: "card_type",
              type: "select",
              dataKey: '',
              data: this.cardTypeList,
              disabled: false,
              required: true,
            }
            this.$refs.gridBody.$refs.myform.reset()
          })
        }
      },
      // {
      //   name: "编辑",
      //   icon: 'md-create',
      //   value: 'BJ',
      //   class: '',
      //   type: 'success',
      //   index: 2,//显示的位置
      //   onClick: function () {
      //     this.$refs.gridBody.model = true
      //     this.$refs.gridBody.title = '编辑'
      //     this.$refs.gridBody.editFormOptions[0][0] = {
      //       title: "卡模板",
      //       field: "card_type",
      //       type: "select",
      //       dataKey: '',
      //       data: this.cardTypeList,
      //       disabled: false,
      //     }
      //     let v = this.getSelectRows()[0]
      //     this.$refs.gridBody.cardMakeId = v.id
      //     this.$refs.gridBody.editFormFields.card_type = v.card_type
      //     this.$refs.gridBody.editFormFields.card_num = v.card_num
      //     this.$refs.gridBody.editFormFields.card_count = v.card_count
      //     this.$refs.gridBody.editFormFields.rule_type = v.rule_type
      //     this.$refs.gridBody.editFormFields.cardno_prefix = v.cardno_prefix
      //     this.$refs.gridBody.editFormFields.start_no = v.start_no
      //     this.$refs.gridBody.editFormFields.random_type = v.random_type != null ? v.random_type.toString() : ''
      //     this.$refs.gridBody.editFormFields.cardno_suffix = v.cardno_suffix
      //     this.$refs.gridBody.editFormFields.note = v.note
      //     this.$refs.gridBody.editFormFields.time_type = v.time_type
      //     if (v.time_type == 0) {
      //       this.$refs.gridBody.editFormFields.cardno_gdrq = [new Date(v.begindate), new Date(v.enddate)]
      //     } else {
      //       this.$refs.gridBody.editFormFields.card_day = v.card_day
      //     }
      //     console.log(this.$refs.gridBody.cardMakeId);
      //   }
      // }
    ], box: [], detail: []
  },//扩展的按钮
  methods: {//事件扩展
    getFormOption (field) {
      let option;
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == field) {
            option = item;
          }
        })
      })
      return option;
    },
    onInit () {
      // 不显示多选框
      //;
      // 显示序号
      //;
      // 开启单选
      //;
      this.$store.getters.data().viewPageTest = this;
      let params = {
        order: "desc",
        page: 1,
        rows: 30,
        sort: "cardtypeid",
        wheres: "[]"
      }
      this.cardTypeList = []
      this.http.post("/api/Mebcardtype/getPageData", params).then(res => {
        res.rows.forEach(i => {
          let obj = {
            key: i.cardtypeid,
            value: i.cardtypename
          }
          this.cardTypeList.push(obj)
        })
      })
    },
    rowClick ({ row, column, event }) { //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
    delBefore (ids, rows) {
      let p = {
        order: "desc",
        page: 1,
        rows: 10000,
        sort: "createtime",
        wheres: `[{\"name\":\"card_batch\",\"value\":\"${rows[0].card_batch}\",\"displayType\":\"text\"},{\"name\":\"operatorID\",\"value\":\"3707\",\"displayType\":\"text\"}]`
      }
      this.http.post('/api/Mebcard/getPageData', p).then(res => {
        if (res.rows != null && res.rows.length != 0) {
          this.$Message.error('此制卡下有会员卡，暂不支持删除')
        } else {
          this.http.post('/api/member_card_make/del', [ids.toString()]).then(res => {
            this.refresh()
          })
        }
      })
    },
  }
};
export default extension;